using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace qPrintComponent
{
    //typedef struct _DRIVER_INFO_6 {
    //  DWORD      cVersion;                0
    //  LPTSTR     pName;                   1   
    //  LPTSTR     pEnvironment;            2
    //  LPTSTR     pDriverPath;             3
    //  LPTSTR     pDataFile;               4
    //  LPTSTR     pConfigFile;             5
    //  LPTSTR     pHelpFile;               6
    //  LPTSTR     pDependentFiles;         7
    //  LPTSTR     pMonitorName;            8
    //  LPTSTR     pDefaultDataType;        9
    //  LPTSTR     pszzPreviousNames;       10
    //  FILETIME   ftDriverDate;            11,12,13
    //  DWORDLONG  dwlDriverVersion;        14,15
    //  LPTSTR     pszMfgName;              16
    //  LPTSTR     pszOEMUrl;               17
    //  LPTSTR     pszHardwareID;           18
    //  LPTSTR     pszProvider;             19
    //} DRIVER_INFO_6, *PDRIVER_INFO_6, *LPDRIVER_INFO_6;

    public sealed class DriverInfo6 : qSafeDriverInfo
    {
        public DriverInfo6(SafeHandle PrinterHandle)
            : base(PrinterHandle, 6)
        { }
        
        public DriverInfo6(IntPtr MemoryHandle)
            : base(MemoryHandle, 6)
        { }

        public override string ToString()
        {
            return Provider;
        }

        [Description(@"Specifies the operating system version for which the driver was written. Currently it can be the following. Value Meaning 3 Driver for Windows 2000/XP.")]
        public int Version
        {
            get { return GetIntField(0); }
        }
        [Description(@"The name of the driver (for example, QMS 810).")]
        public string Name
        {
            get { return GetStringField(1); }
        }
        [Description(@"The environment for which the driver was written (for example, Windows NT x86, Windows IA64, Windows x64, Windows NT R4000, Windows NT Alpha_AXP, Windows 4.0, or Windows NT PowerPC).")]
        public string Environment
        {
            get { return GetStringField(2); }
        }
        [Description(@"The file that contains the device driver (for example, C:\DRIVERS\Pscript.dll).")]
        public string DriverPath
        {
            get { return GetStringField(3); }
        }
        [Description(@"The file that contains driver data (for example, C:\DRIVERS\Qms810.ppd).")]
        public string DataFile
        {
            get { return GetStringField(4); }
        }
        [Description(@"Tthe device driver's configuration dynamic-link library (for example, C:\DRIVERS\Pscrptui.dll).")]
        public string ConfigFile
        {
            get { return GetStringField(5); }
        }
        [Description(@"The device driver's help file (for example, C:\DRIVERS\Pscrptui.hlp).")]
        public string HelpFile
        {
            get { return GetStringField(6); }
        }
        [Description(@"The files the driver depends on. Each file name is separated by a backslash and a null character (for example, Pscript.dll\0QMS810.ppd\0Pscriptui.dll\0Pscriptui.hlp\0Pstest.txt\0\0).")]
        public string DependentFiles
        {
            get { return GetStringField(7); }
        }
        [Description(@"A language monitor (for example, 'PJL monitor'). This member can be NULL and should be specified only for printers capable of bidirectional communication.")]
        public string MonitorName
        {
            get { return GetStringField(8); }
        }
        [Description(@"The default data type of the print job (for example, 'EMF').")]
        public string DefaultDataType
        {
            get { return GetStringField(9); }
        }
        [Description(@"Any previous printer driver names that are compatible with this driver (for example, OldName1\0OldName2\0\0).")]
        public string PreviousNames
        {
            get { return GetStringField(10); }
        }
        [Description(@"The date of the driver package, as coded in the driver files.")]
        public string FileTime
        {
            get
            {
                long l = GetLongField(11);
                if (l == 0) return "Unknown";
                return DateTime.FromFileTimeUtc(l).ToShortDateString();    
            }
        }
        [Description(@"Version number of the driver. This comes out of the version structure of the driver.")]
        public Int64 Fileversion
        {
            get { return GetLongField(14); }
        }
        [Description(@"The manufacturer's name.")]
        public string ManufacterName
        {
            get { return GetStringField(16); }
        }
        [Description(@"The URL for the manufacturer.")]
        public string ManufacterUrl
        {
            get { return GetStringField(17); }
        }
        [Description(@"The hardware ID for the printer driver.")]
        public string ManufacterHardWareId
        {
            get { return GetStringField(18); }
        }
        [Description(@"The provider of the printer driver (for example, 'Microsoft Windows 2000').")]
        public string Provider
        {
            get { return GetStringField(19); }
        }
    }
}
